package util;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @author 李栋
 * @version 1.0.0
 * @className SetTest.java
 * @createTime 2021年08月15日 11:59:00
 */
public class SetTest {

    private static final Logger logger = LoggerFactory.getLogger(SetTest.class);

    @Test
    public void setTest() {
        Set<String> set = new HashSet<>();
        set.add("methodTest");
        set.add("test3");
        set.add("test2");
        logger.info(set.toString());
    }

    /**
     * TreeSet 排序
     */
    @Test
    public void treeSetTest() {
        TreeSet<String> set = new TreeSet<String>((Comparator) (o1, o2) -> {
            int length1 = String.valueOf(o1).length();
            int length2 = String.valueOf(o2).length();
            if (length1 == length2) return 1;
            return Integer.compare(length1, length2);
        });
        set.add("zhangsan");
        set.add("test");
        set.add("lisi");
        set.add("1234");
        set.add("wangwu");
        logger.info(String.valueOf(set));
    }

    @Test
    public void testOne(){
        String str = "张三 李四 王五 ";
        String[] split = str.trim().split(" ");
        Set<String> set = Arrays.stream(split).collect(Collectors.toSet());
        logger.info(set.toString());
    }
}
